package cn.lijiguo.concurrency.part1.threadobjectmethods;

/**
 * JoinInterrupt
 * 演示 join() 期间被中断的效果
 * @author lijiguo
 * @date 2020/1/7 14:13
 */
public class JoinInterrupt {

    public static void main(String[] args) {
        Thread main = Thread.currentThread();

        Thread t1 = new Thread(() -> {
            try {
                main.interrupt();

                Thread.sleep(5000);
                System.out.println(Thread.currentThread().getName() + " 执行完毕~~~");
            } catch (InterruptedException e) {
                System.out.println("子线程中断！！！");
                e.printStackTrace();
            }
        }, "t1");

        t1.start();
        System.out.println("等待子线程运行完毕");
        try {
            t1.join();
        } catch (InterruptedException e) {
            System.out.println(Thread.currentThread().getName() + " 线程被中断了！！！");
            t1.interrupt();
            e.printStackTrace();
        }
        System.out.println("子线程执行完毕");
    }
}
